/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.demo.gulimall.common.utils;

import com.alibaba.fastjson.JSON;
import org.apache.http.HttpStatus;
import org.apache.ibatis.type.TypeReference;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 *
 * @author Mark sunlightcs@gmail.com
 */
public class R<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private T data;

	private Integer code;

	private String msg;

	public <T> R() {
		this.setMsg("success");
		this.setCode(0);
	}

	public static R error() {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
	}

	public static R error(String msg) {
		return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
	}

	public static <T> R<T> error(int code, String msg) {
		R<T> r = new R<T>();
		r.setCode(code);
		r.setMsg(msg);
		return r;
	}

	public static <T> R<T> ok(String msg) {
		R<T> r = new R<T>();
		r.setMsg(msg);
		return r;
	}

	public static <T> R<T> ok(T data) {
		R<T> r = new R<T>();
		r.setData(data);
		return r;
	}

	public static <T> R<T> ok() {
		return new R<T>();
	}




	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}


	public Integer getCode() {
		return this.code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}


	public Boolean isSuccess(){
		return code == 0;
	}
}
